import 'package:bxultimate/app/router/router_name.dart';
import 'package:bxultimate/data/request/shop_request.dart';
import 'package:bxultimate/domain/shop/Shop.dart';
import 'package:get/get.dart';

import 'state.dart';

class ShopCategoryListController extends GetxController {
  final ShopCategoryListState state = ShopCategoryListState();

  var pageSize = 10;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    state.title = Get.arguments['name'];
    getData(true);
  }

  getData(bool isClear) async {
    var list = await ShopRequest.getShopListByCategory(
        state.page, pageSize, Get.arguments["id"]);
    if (isClear) {
      state.shopList = list;
    } else {
      state.shopList.addAll(list);
    }
  }

  Future<void> onRefresh() async {
    state.page = 1;
    await getData(true);
  }

  Future<void> onLoad() async {
    state.page++;
    await getData(false);
  }

  void toArticleDetail(Shop shop) {
    Get.toNamed(RouterName.shopDetail, arguments: shop.id);
  }
}
